import javax.swing.*;
import java.awt.*;

public class Register extends JLabel {
    double res;
    char operation;

    double getRes() {
        return res;
    }

    void setRes(double d) {
        res = d;
    }

    char getOperation() {
        return operation;
    }

    void setOperation(char c) {
        operation = c;
    }

    void updateText() {
        this.setText(res + "");
        if(operation != '\0') {
            this.setText(this.getText() + operation);
        }
    }

    void reset() {
        setRes(0);
        setOperation('\0');
    }

    void calculate(double d) {
        if(operation == '/' && d == 0) {
            this.setText("Error");
            reset();
            return;
        }

        if(operation == '+') res += d;
        else if(operation == '-') res -= d;
        else if(operation == '*') res *= d;
        else if(operation == '/') res /= d;
        else if(operation == '%') res %= d;

        setOperation('\0');
    }

    public Register() {
        this.setForeground(Color.GRAY);
    }
}
